package com.algorithm.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by mi on 2016/11/7.
 */
public class FileOperate {

    public static String[] readFileByLines(String filename) {
        File file = new File(filename);
        List<String> lines = new ArrayList<>();
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            String strLine;
            while( (strLine = bufferedReader.readLine()) != null){
                lines.add(strLine);
            }
            bufferedReader.close();
            return lines.toArray(new String[lines.size()]);
        } catch (FileNotFoundException e) {
            System.out.println("file:"+ filename + "not found");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
